package com.v2.request;


import com.google.gson.Gson;
import com.v2.utils.okhttp.OkHttpRequestCallback;
import com.v2.utils.okhttp.OkHttpUtil;
import com.zou.lotterylucky.Constants;

import java.util.HashMap;
import java.util.Map;

public class RequestCenter {

    //√
    public static void login(String machine_number, String password, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("machine_number", machine_number);
        map.put("password", password);
        OkHttpUtil.post(Constants.SERVER_URL + "user/appLogin", new Gson().toJson(map), callback);
    }

    //√
    public static void appPing(String machine_number, String password, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("machine_number", machine_number);
        map.put("password", password);
        OkHttpUtil.post(Constants.SERVER_URL + "region/appPing", new Gson().toJson(map), callback);
    }

    //√
    public static void appGetOrders(String machine_number, String serial_number, String is_winner, String startTime, String endTime, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("machine_number", machine_number);
        map.put("serial_number", serial_number);
        map.put("is_winner", is_winner);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        OkHttpUtil.post(Constants.SERVER_URL + "order/appGetOrders", new Gson().toJson(map), callback);
    }

    //√
    public static void deleteOrderBySerialNumber(String serial_number, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("serial_number", serial_number);
        OkHttpUtil.post(Constants.SERVER_URL + "order/deleteBySerialNumber", new Gson().toJson(map), callback);
    }

    //√
    public static void deleteOrderById(String order_id, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", order_id);
        OkHttpUtil.post(Constants.SERVER_URL + "order/deleteById", new Gson().toJson(map), callback);
    }

    //√
    public static void updateOrderPaid(String id, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        OkHttpUtil.post(Constants.SERVER_URL + "order/updatePaid", new Gson().toJson(map), callback);
    }

    //√
    public static void getSerialNumber(OkHttpRequestCallback callback) {
        OkHttpUtil.post(Constants.SERVER_URL + "order/getSerialNumber", new HashMap<>(), callback);
    }

    //√
    public static void getServerTime(OkHttpRequestCallback callback) {
        OkHttpUtil.get(Constants.SERVER_URL + "test/getServerTime", callback);
    }

    //√
    public static void saveOrder(String json, OkHttpRequestCallback callback) {
        OkHttpUtil.post(Constants.SERVER_URL + "order/add", json, callback);
    }

    //√
    public static void appGetPrizesFromWinningHistory(String machine_number, String startTime, String endTime, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("machine_number", machine_number);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        OkHttpUtil.post(Constants.SERVER_URL + "winHistory/appGetPrizes", new Gson().toJson(map), callback);
    }

    //√
    public static void getWinningLotteryNumbers(String startTime, String endTime, int before, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("before", "" + before);
        OkHttpUtil.post(Constants.SERVER_URL + "win/list", new Gson().toJson(map), callback);
    }

    //√
    public static void appGetOrdersByDateRange(String machine_number, String startTime, String endTime, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("machine_number", machine_number);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        OkHttpUtil.post(Constants.SERVER_URL + "winHistory/listByDate", new Gson().toJson(map), callback);
    }


    //XXX
    @Deprecated
    public static void payOrder(String order_id, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("order_id", order_id);
        OkHttpUtil.post(Constants.SERVER_URL + "saveOrderPaymentStatus", callback);
    }

    @Deprecated
    public static void getOrderBySerialNumber(String machine_number, String serial_number, OkHttpRequestCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("machine_number", machine_number);
        map.put("serial_number", serial_number);
        OkHttpUtil.post(Constants.SERVER_URL + "getOrderBySerialNumber", new Gson().toJson(map), callback);
    }


}
